module controller.search_ctrl;

import vibe.http.server : HTTPServerRequest, HTTPServerResponse;

import service.article_service;
import service.cate_service;

import darktemple.render;

/** 
 * 文章搜索页
 */
void getArticleSearchPage (scope HTTPServerRequest req, scope HTTPServerResponse res)
{
    string keyword = req.query.get("keyword", "");
    if (keyword == "")
    {
        return res.writeBody("错误的请求", "text/html; charset=utf-8");
    }

    auto categoryList = getCategoryList();
    auto articleList = searchArticlesByKeyword(keyword);

    string html = renderFile!("search.tmpl", categoryList, articleList, keyword);
    res.writeBody(html, "text/html; charset=utf-8");
}
